Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple scopes support to string-format rule #1009

Merged

Conversation

KirillSluchaev
Copy link
Contributor

Hi, I added new feature.

I describe my motivation in issue.

I added some tests and refactor old one little bit, becouse change error message.
My code almost follow the coding style of the rest of the repository.
Build passed.

Closes #1008

if err != nil {
w.parseError("unable to parse argument number in rule scope", ruleNum, 0)
// Parse rule scopes
rawScopes := strings.Split(rule[0], ",")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried about the fact people may use , , or ,, or , as delimiter.

So maybe, you could use strings.TrimSpace on the rawScope in the for loop

Also, xhecking that the rawScope is not empty could avoid surprises and bugs

I'm pretty sure someone would face a

foo,,bar, or foo , , bar

No matter the implementation choice to either clean them, or forbid them. It should be covered by a test

@ccoVeille
Copy link
Contributor

I like the proposal and the way you implemented it, I found a few things that might be improved maybe

@KirillSluchaev
Copy link
Contributor Author

Add behavior from comment

regexp *regexp.Regexp
negated bool
errorMessage string
}

type stringFormatSubruleScopes []*stringFormatSubruleScope
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: why is that a slice of pointers? (not a slice of values)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw one video on youtube where this two approaches were compared and slice of pointers use less memory little bit)

@KirillSluchaev
Copy link
Contributor Author

@chavacava Hi, could you review my PR, please)

@@ -775,6 +775,7 @@ Example:
["core.WriteError[1].Message", "/^([^A-Z]|$)/", "must not start with a capital letter"],
["fmt.Errorf[0]", "/(^|[^\\.!?])$/", "must not end in punctuation"],
["panic", "/^[^\\n]*$/", "must not contain line breaks"],
["fmt.Errorf[0],core.WriteError[1].Message", "/^.*%w.*$/", "must not contains '%w'"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
["fmt.Errorf[0],core.WriteError[1].Message", "/^.*%w.*$/", "must not contains '%w'"],
["fmt.Errorf[0],core.WriteError[1].Message", "/^.*%w.*$/", "must not contain '%w'"],

Using this conf the rule (wrongly) matches things like

return fmt.Errorf("not implemented: AlterableDoltTable.DropPrimaryKey()"

@chavacava
Copy link
Collaborator

Thanks for the PR!
I've tested the rule using the example configuration in the documentation and against real code bases (https://github.com/dolthub/dolt for example) and the rule spots, what I think, false positives (see my previous comment)

@KirillSluchaev
Copy link
Contributor Author

I made mistake in rule example. I fixed it, you can check again. Regexp rule should be inversed to lint only strings which contains '%w'

@chavacava chavacava merged commit a638ed6 into mgechev:master Aug 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple scopes to string-format rule
4 participants